package api;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Ann Raboschuk
 */
public class Person implements Serializable
{
   private static final long serialVersionUID = 1L;
   private Long id;
   private String surname, name;
   private Integer age;
   private Character sex;
   private String email;
   private Set<Phone> phones = new HashSet<Phone>();
   private Set<Address> addresses = new HashSet<Address>();

   public Person()
   {
   }

   public Person(String surname, String name, Integer age, Character sex,
         String email, Set<Phone> phones, Set<Address> addresses)
   {
      this.surname = surname;
      this.name = name;
      this.age = age;
      this.sex = sex;
      this.email = email;
      this.phones = phones;
      this.addresses = addresses;
   }

   public String toString()
   {
      return "" + id.toString() + "; " + surname + "; " + name + "; " + age
            + "; " + sex + "; " + email + "; " + phones + "; " + addresses;
   }

   public static Person fromString(String object)
   {
      String[] fields = object.split("; ");
      Person person = new Person(fields[1], fields[2], Integer
            .parseInt(fields[3]), fields[4].charAt(0), fields[5],
            new HashSet<Phone>(), new HashSet<Address>());
      person.setId(Long.parseLong(fields[0]));
      return person;
   }

   public Long getId()
   {
      return id;
   }

   public String getSurname()
   {
      return surname;
   }

   public String getName()
   {
      return name;
   }

   public Integer getAge()
   {
      return age;
   }

   public Character getSex()
   {
      return sex;
   }

   public String getEmail()
   {
      return email;
   }

   public void setId(Long id)
   {
      this.id = id;
   }

   public void setSurname(String surname)
   {
      this.surname = surname;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   public void setAge(Integer age)
   {
      this.age = age;
   }

   public void setSex(Character sex)
   {
      this.sex = sex;
   }

   public void setEmail(String email)
   {
      this.email = email;
   }

   public Set<Phone> getPhones()
   {
      return phones;
   }

   public Set<Address> getAddresses()
   {
      return addresses;
   }

   public void setPhones(Set<Phone> phones)
   {
      this.phones = phones;
   }

   public void setAddresses(Set<Address> addresses)
   {
      this.addresses = addresses;
   }
}
